package cn.wolfcode.luowowo.acticle.service.impl;


import cn.wolfcode.luowowo.acticle.domain.Scenery;
import cn.wolfcode.luowowo.acticle.domain.SceneryContent;
import cn.wolfcode.luowowo.acticle.mapper.SceneryContentMapper;
import cn.wolfcode.luowowo.acticle.mapper.SceneryMapper;
import cn.wolfcode.luowowo.acticle.query.SceneryQuery;
import cn.wolfcode.luowowo.acticle.service.ISceneryService;
import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


@Service
@Transactional
public class SceneryServiceImpl implements ISceneryService {

    @Autowired
    private SceneryMapper sceneryMapper;

    @Autowired
    private SceneryContentMapper sceneryContentMapper;


    @Override
    public PageInfo query(SceneryQuery qo) {
        PageHelper.startPage(qo.getCurrentPage(), qo.getPageSize());

        return new PageInfo(sceneryMapper.selectForList(qo));
    }

    @Override
    public Scenery get(Long id) {
        Scenery scenery = sceneryMapper.selectByPrimaryKey(id);
        SceneryContent sceneryContent = sceneryContentMapper.selectByPrimaryKey(id);
        scenery.setSceneryContent(sceneryContent);
        return scenery;
    }

    @Override
    public List<Scenery> querySceneryByDestId(Long destId) {
        SceneryQuery qo = new SceneryQuery();
        qo.setDestId(destId);
        PageHelper.startPage(qo.getCurrentPage(), 3);
        return sceneryMapper.selectForList(qo);
    }


    @Override
    public Long saveOrUpdate(Scenery scenery) {
        //TODO...
        return null;
    }


    @Override
    public List<Scenery> list() {
        return sceneryMapper.selectAll();
    }
}
